import axios from "axios"; // 引用axios
import {ElMessageBox} from 'element-plus';
import { getToken } from "@/utils/token"
const instance = axios.create({
    //   baseURL: config.baseUrl.dev,
    baseURL: process.env.NODE_ENV === 'production'? '/' :'/api',
    timeout: 60000,
});
// request拦截器
instance.interceptors.request.use(config => {
    config.headers['Token'] = getToken()
    return config

}, error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
})
//get请求
export function get(url, params = {}) {
    return new Promise((resolve, reject) => {
        instance.get(url, {
            params: params,
        }).then((response) => {
            resolve(response.data);
        }).catch((err) => {
            reject(err);
        });
    });
}
//post请求
export function post(url, data = {}) {
    return new Promise((resolve, reject) => {
        instance.post(url, data).then((response) => {
            resolve(response.data);
        },(err) => {
            reject(err);
        });
    });
}
